package team.hyznrj.studentsys.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import team.hyznrj.studentsys.dto.PowerDto;
import team.hyznrj.studentsys.dto.RoleDto;
import team.hyznrj.studentsys.entity.account.FunctionInfo;
import team.hyznrj.studentsys.service.LoginPowerRegisterService;
import team.hyznrj.studentsys.service.RoleService;
@Service
@Slf4j
public class LoginPowerRegisterServiceImpl implements  LoginPowerRegisterService{
	@Autowired
	RoleService roleService;
	@Override
	public List<String> getPowerUrls(String roleId) {
		if(!StringUtils.isEmpty(roleId)){
			List<String> urls=new ArrayList<>();
			RoleDto findRoleDtoByRoleId = roleService.findRoleDtoByRoleId(roleId);
			log.info("RoleDto:"+findRoleDtoByRoleId);
			if(findRoleDtoByRoleId!=null){
				List<PowerDto> powerDtoList = findRoleDtoByRoleId.getPowerDtoList();
				log.info("powerDtoList:"+powerDtoList);
				for(PowerDto dto:powerDtoList){
					List<FunctionInfo> functionInfoList = dto.getFunctionInfoList();
					log.info("functionInfoList:"+functionInfoList);
					for(FunctionInfo funInfo:functionInfoList){
						String functionUrl = funInfo.getFunctionUrl();
						if(!urls.contains(functionUrl)){
							urls.add(functionUrl);
						}
					}
				}
			}
			log.info(roleId+" get authentication powers: "+urls);
			return urls;
		}
		return null;
	}

}
